package com.xinke.edu.mypetadoption.fragment.Home.adpter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter4.BaseQuickAdapter;
import com.chad.library.adapter4.viewholder.QuickViewHolder;
import com.xinke.edu.mypetadoption.R;
import com.xinke.edu.mypetadoption.entity.Product;
import com.xinke.edu.mypetadoption.util.DensityUtil;

public class ProductAdpter extends BaseQuickAdapter<Product, QuickViewHolder> {

    @Override
    protected void onBindViewHolder(@NonNull QuickViewHolder quickViewHolder, int i, @Nullable Product product) {
        ImageView img = quickViewHolder.getView(R.id.img);
        int width = (DensityUtil.getSreenWidth(getContext())-30)/2;
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width,width*2/3);
        img.setLayoutParams(lp);
        Glide.with(getContext()).load(product.getCoverImage()).into(img);
        quickViewHolder.setText(R.id.name,product.getName());
        quickViewHolder.setText(R.id.price,"￥"+product.getPrice());
    }

    @NonNull
    @Override
    protected QuickViewHolder onCreateViewHolder(@NonNull Context context, @NonNull ViewGroup viewGroup, int i) {
        return new QuickViewHolder(R.layout.item_product,viewGroup);
    }
}
